﻿@using PagedList;
@using PagedList.Mvc;
@model IPagedList<MVCDemoEF.Models.EmployeeEx>
@{
    ViewBag.Title = "Index";
}
<link href="~/Content/PagedList.css" rel="stylesheet" type="text/css" />
<div style="font-family: Arial">
    <h2>
        Index</h2>
    <p>
        @Html.ActionLink("Create New", "Create")
    </p>
    <p>
        @using (Html.BeginForm("Index", "Search", FormMethod.Get))
        {
            <b>Search By: </b> @Html.RadioButton("searchBy", "Name", true) <text> Name</text>
            @Html.RadioButton("searchBy", "Gender") <text>Gender</text><br />
            @Html.TextBox("search")
            <input type="submit" value="search" />
        }
    </p>
    <table border="1">
        <tr>
            <th>
                @Html.ActionLink("Name", "Index", new { sortBy = ViewBag.SortNameParameter, searchBy = Request.QueryString["searchBy"], search = Request.QueryString["search"] })
            </th>
            <th>
                @Html.ActionLink("Gender", "Index", new { sortBy = ViewBag.SortGenderParameter, searchBy = Request.QueryString["searchBy"], search = Request.QueryString["search"] })                
            </th>
            <th>
                @Html.DisplayNameFor(model => model.First().Age)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.First().HireDate)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.First().EmailAddress)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.First().Salary)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.First().PersonalWebSite)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.First().Photo)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.First().AlternateText)
            </th>
            <th>
                Action
            </th>
        </tr>
        @if (Model.Count() == 0)
        {
            <tr>
                <td colspan="10">
                    No rows match search criteria
                </td>
            </tr>
        }
        else
        {
            foreach (var item in Model)
            {
                <tr> <td>
                @Html.DisplayFor(modelItem => item.FullName)
                </td> <td>
                @Html.DisplayFor(modelItem => item.Gender)
                </td> <td>
                @Html.DisplayFor(modelItem => item.Age)
                </td> <td>
                @Html.DisplayFor(modelItem => item.HireDate)
                </td> <td>
                @Html.DisplayFor(modelItem => item.EmailAddress)
                </td> <td>
                @Html.DisplayFor(modelItem => item.Salary)
                </td> <td>
                @Html.DisplayFor(modelItem => item.PersonalWebSite)
                </td> <td>
                @Html.DisplayFor(modelItem => item.Photo)
                </td> <td>
                @Html.DisplayFor(modelItem => item.AlternateText)
                </td> <td>
                @Html.ActionLink("Edit", "Edit", new { id = item.Id }) |
                @Html.ActionLink("Details", "Details", new { id = item.Id }) |
                @Html.ActionLink("Delete", "Delete", new { id = item.Id })
            </td> </tr>
            }
        }
    </table>
    @Html.PagedListPager(Model, page => Url.Action("Index", new { page, searchBy = Request.QueryString["searchBy"], search = Request.QueryString["search"], sortBy = Request.QueryString["sortBy"] }),
    new PagedListRenderOptions() { Display=PagedListDisplayMode.IfNeeded, DisplayPageCountAndCurrentLocation=true, DisplayItemSliceAndTotal=true})

</div>
